package com.sy.controller.inventory;

import com.sy.bean.inventory.Allocate;
import com.sy.bean.inventory.AllocateQuery;
import com.sy.common.bean.PageBean;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.common.utils.BeanOfMap;
import com.sy.service.inventory.AllocateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "调拨单")
@RequestMapping("/api/Allocate")
public class AllocateController extends BaseController {

    @Autowired
    AllocateService allocateService;

    @PostMapping("/query")
    @ApiOperation(value = "查询调拨单列表")
    public ResultBean query(@RequestBody AllocateQuery query){

        PageBean<Allocate> list = allocateService.query(BeanOfMap.bom(query));
        return success("查询成功",list);
    }

    @GetMapping("/queryById")
    @ApiOperation(value = "根据id查询调拨单")
    public ResultBean queryById(int id){
        List<Allocate> list = allocateService.queryById(id);
        return success("查询成功",list);
    }


    @GetMapping("/examine")
    @ApiOperation(value = "审核调拨单")
    public ResultBean examine(@RequestParam("reviewers") String reviewers,@RequestParam("id") int id,@RequestParam("type") int type){
        int rs = allocateService.examineById(reviewers,id,type);
        return rs == 1 ? success("审核成功") : fail("审核失败");
    }



    @PostMapping("/saveAllocate")
    @ApiOperation(value = "新增调拨单")
    public ResultBean saveAllocate(@RequestBody Allocate allocate){
        int rs = allocateService.insertAllocate(allocate);
        return rs == 1 ? success("新增成功") : fail("新增失败");
    }



}
